<select name="<?php echo $name ?>">

    <?php
    foreach ($datasource as  $data) {
    ?>
        <option <?php echo isset($value) && $value == $data[$realvalue] ? 'selected' : '' ?> value="<?php echo $data[$realvalue] ?>"><?php echo $data[$displayvalue] ?></option>
    <?php
    }
    ?>

</select>